import type { BaseEntity, ID, PageQuery } from '#/api/common';

import { requestClient } from '#/api/request';

const baseUrl = '/ur_biz/sys_dept';

export interface SysDept extends BaseEntity {
  deptId: ID;
  parentId: ID;
  ancestors: string;
  deptName: string;
  status: string;
  deptSort: number;
  contact: string;
  email: string;
  children: SysDept[];
}

export function listDept(params?: PageQuery) {
  return requestClient.get<SysDept[]>(`${baseUrl}/list`, { params });
}

export function getDept(deptId: ID) {
  return requestClient.get<SysDept>(`${baseUrl}/${deptId}`);
}

export function addDept(data: SysDept) {
  return requestClient.post(`${baseUrl}/add`, data);
}

export function editDept(data: SysDept) {
  return requestClient.post(`${baseUrl}/edit`, data);
}

/**
 * 注意这里只允许单删除
 * @param deptId ID
 * @returns void
 */
export function delDept(deptId: ID) {
  return requestClient.post(`${baseUrl}/remove`, deptId);
}
